import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

import vuexPersist from "vuex-persist";
export default new Vuex.Store({
  state: {
    history: [],
  },
  mutations: {
    search(state, val) {
      if (state.history.length < 3) {
        state.history.unshift(val);
      } else {
        state.history.pop();
        state.history.unshift(val);
      }
    },
    clear(state) {
      state.history = [];
    },
  },
  actions: {},
  modules: {},
  plugins: [
    new vuexPersist({
      storage: window.localStorage,
    }).plugin,
  ],
});
